package Demo1;

import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 34255
 * Date: 2024-07-13
 * Time: 15:18
 */
public class Test {
    public int evalRPN(String[] tokens) {
        Stack<String> stack = new Stack<>();
        for(int i = 0;i < tokens.length;i++){
            String ret = tokens[i];
            if(!ret.equals("+") && !ret.equals("-") && !ret.equals("*") && !ret.equals("/")){
                stack.push(ret);
            }else{
                String s2 = stack.pop();
                String s1 = stack.pop();
                switch(ret){
                    case "+":
                        stack.push("" + (Integer.parseInt(s1) + Integer.parseInt(s2)));
                        break;
                    case "-":
                        stack.push("" + (Integer.parseInt(s1) - Integer.parseInt(s2)));
                        break;
                    case "*":
                        stack.push("" + (Integer.parseInt(s1) * Integer.parseInt(s2)));
                        break;
                    case "/":
                        stack.push( "" + (Integer.parseInt(s1) + Integer.parseInt(s2)));
                        break;
                }
            }
        }
        return Integer.parseInt(stack.pop());
    }

    public static boolean IsPopOrder (int[] pushV, int[] popV) {
        Stack<Integer> stack = new Stack<>();
        int j = 0;
        for(int i = 0;i < pushV.length;i++){
            stack.push(pushV[i]);
            while(j < popV.length && (!stack.isEmpty()) && stack.peek() == popV[j]){//多次相等
                stack.pop();
                j++;
            }
        }
        return stack.isEmpty();
    }
    public static void main(String[] args) {
        int[] arr1 = {2,1,0};
        int[] arr2 = {1,2,0};

        boolean ret = IsPopOrder(arr1, arr2);
        System.out.println(ret);
    }
}
